package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.ProjRequestFundsPlanLogic;
import cn.topevery.garden.entity.dto.ProjRequestFundsPlanDTO;
import cn.topevery.garden.entity.dto.ProjRequestFundsPlanFilesDTO;
import cn.topevery.garden.entity.query.ProjRequestFundsPlanQuery;
import cn.topevery.garden.entity.vo.ProjRequestFundsPlanVO;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 项目请款计划表
 *
 * @author code-generate
 * @date 2022-11-02
 */
@Api(tags = "工程项目-项目请款计划表")
@RestController
@RequestMapping("/projRequestFundsPlan")
public class ProjRequestFundsPlanController extends BaseController {

    @Autowired
    ProjRequestFundsPlanLogic projRequestFundsPlanLogic;

    /**
     * 获取项目请款计划表列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取项目请款计划表列表")
    @PostMapping("/list")
    public JsonResult<List<ProjRequestFundsPlanVO>> list(@RequestBody ProjRequestFundsPlanQuery query) {
        return JsonResult.ok(projRequestFundsPlanLogic.list(query));
    }

    /**
     * 获取项目请款计划表分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取项目请款计划表分页列表")
    @PostMapping("/listPage")
    public JsonResult<DataPager<ProjRequestFundsPlanVO>> listPage(@RequestBody ProjRequestFundsPlanQuery query) {
        return JsonResult.ok(projRequestFundsPlanLogic.listPage(query));
    }

    /**
     * 根据自增ID批量删除
     *
     * @param dto
     * @return
     */
    @ApiOperation("根据自增ID批量删除")
    @PostMapping("/deleteBatchById")
    public JsonResult<Boolean> deleteBatchById(@RequestBody ProjRequestFundsPlanDTO dto) {
        projRequestFundsPlanLogic.delete(getUser().userId, dto.getIds());
        return JsonResult.ok(true);
    }

    /**
     * 新增/编辑 项目请款计划表信息
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增/编辑 项目请款计划表信息")
    @PostMapping("/saveOrUpdate")
    public JsonResult<Boolean> saveOrUpdate(@Valid @RequestBody ProjRequestFundsPlanFilesDTO dto) {
        projRequestFundsPlanLogic.insertOrUpdate(getUser().userId, dto);
        return JsonResult.ok(true);
    }

    /**
     * 根据自增id获取详情
     *
     * @param id
     * @return
     */
    @ApiOperation("根据自增id获取详情")
    @GetMapping("/getVOById")
    public JsonResult<ProjRequestFundsPlanVO> getVOById(@RequestParam(value = "id") Integer id) {
        return JsonResult.ok(projRequestFundsPlanLogic.getVOById(id));
    }

    @ApiOperation("导出项目请款计划表信息")
    @GetMapping("/export")
    public void export(ProjRequestFundsPlanQuery query, HttpServletResponse response) {
        List<ProjRequestFundsPlanVO> list = projRequestFundsPlanLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "项目请款计划表", "sheet1", ProjRequestFundsPlanVO.class, "项目请款计划表", response);
    }
}
